<!doctype html>
<%@ page contentType="text/html;charset=utf-8" pageEncoding="utf-8"
	language="java"%>
<%@ include file="/jsp/mobile/include/include.jsp"%>
<html lang="cn">
<head>
<%@ include file="/jsp/mobile/include/header.jsp"%>
<title>分享注册</title>
</head>
<body class="nobg">
	<div class="main">
		<div class="sinfo">
			<div class="sfb">
				<i class="ico ico32"></i> <input id="telephone" name="telephone"
					type="text" class="text" placeholder="请输入手机号码">
			</div>
			<div class="sfb sfb2">
				<i class="ico ico33"></i> <input id="verifyCode" name="verifyCode"
					type="text" class="text" placeholder="请输入验证码"> <a
					id="sendVerifyCode" href="javascript:sendVerifyCode();" class="yzm">获取验证码</a>
			</div>
		</div>
		<div class="ciTab">
			<ul>
				<li><span class="tit">登录密码</span> <input id="loginPassword"
					name="loginPassword" type="password" class="text"
					placeholder="输入8位字符密码"></li>
				<li><span class="tit">确认密码</span> <input id="confirmPassword"
					name="confirmPassword" type="password" class="text"
					placeholder="重新输入登录密码"></li>
				<li style="min-height: 1px;"></li>
				<input id="invitationCode" 	name="invitationCode" type="hidden" class="text"
													value="${model.sysAccount}">
			</ul>
		</div>
		<div class="payOk">
			<div class="nbtn mt20">
				<a class="butn" href="javascript:register();">注册</a>
			</div>
		</div>
	</div>
	<div id="notify" style="display: none;">
	<div class="uiMask"></div>
	<div class="opom">
		<p class="red f20">恭喜您，注册成功！</p>
	    <a href="http://m.baoshuxinxxi.com" class="butn mt30" style="padding:10px 0">点击下载APP</a>
	</div>
	</div>
</body>
<script type="text/javascript">
var wait = 60; 
function verifyCodeTime() {
    var _obj = $("#sendVerifyCode");
    if (wait == 0) {
        $(_obj).attr("href", "javascript:sendVerifyCode();");
        $(_obj).html("获取验证码");
        wait = 60;
    } else {
        $(_obj).removeAttr("href");
        $(_obj).html(wait + "秒后获取");
        wait--;
        setTimeout(function() {
                    verifyCodeTime();
                },
                1000);
    }
}
function register() {
	var _msg = '';
    var _verifyCode = $("#verifyCode").val();
    var _loginPassword = $("#loginPassword").val();
    var _confirmPassword = $("#confirmPassword").val();
    if(_verifyCode == '')
    {
    	_msg += "输入验证码";
    }
    if(_loginPassword == '')
	{
		_msg += "输入登陆密码";
	}else if (!checkPassword(_loginPassword)) {
		_msg += "密码必须为8-20位字母数字组合";
	}
    if(_confirmPassword == '')
	{
		_msg += "输入确认密码";
	}    
    if(_confirmPassword != _loginPassword)
	{
		_msg += "两次输入密码不一致";
	}
    
    if (_msg != '') {
        window.openMsg(_msg, 3);
    } else {
    	registerSubmit();
    }
}
function sendVerifyCode() {
	var _telephone = $("#telephone").val().trim();
	var _msg = "";
	if (_telephone == '') {
        _msg += "输入手机号\r\n";
    }else if(!$.phone(_telephone))
    {
    	_msg += "输入手机号不正确\r\n";
    }
	if (_msg == "") {
    $.ajax({
        type: "GET",
        url: "<%=request.getContextPath()%>/mobile/index/sendVerifyCode",
						data : {
							'jsonStr' : '{"telephone":' + _telephone + '}'
						},
						dataType : "json",
						success : function(msg) {
							if (msg.returnCode == "0000") {
								verifyCodeTime();
								window.openMsg("短信已发送", 3);
							} else {
								window.openMsg(msg.returnMsg, 3);
							}
						}
					});
		} else {
			window.openMsg(_msg, 3);
		}
	}
	
function registerSubmit() {
    $.ajax({
        type: "GET",
        url: "<%=request.getContextPath()%>/mobile/index/registerByShare",
			data : {				
				'telephone' : $("#telephone").val(),
				'verifyCode' : $("#verifyCode").val(),
				'invitationCode' : $("#invitationCode").val(),
				'loginPassword' : $("#loginPassword").val(),
				'confirmPassword' : $("#confirmPassword").val()
			},
			dataType : "json",
			success : function(msg) {
				if (msg.returnCode == "0000") {
					$("#notify").show();
				} else {
					window.openMsg(msg.returnMsg, 3);
				}
			}
		});
	}
</script>
</html>